package com.hiultra.archive.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson2.JSON;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.hiultra.archive.domain.*;
import com.hiultra.archive.domain.vo.*;
import com.hiultra.archive.service.*;
import com.hiultra.archive.utils.tool.ToolUtils;
import com.hiultra.common.constant.BusinessConstants;
import com.hiultra.common.core.domain.AjaxResult;
import com.hiultra.common.core.redis.RedisCache;
import com.hiultra.common.exception.ServiceException;
import com.hiultra.common.utils.uuid.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;

import java.net.URISyntaxException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * 外部接口Service业务层处理
 *
 * @author ls
 * @date 2022-07-28
 */
@SuppressWarnings("AliMissingOverrideAnnotation")
@Service
public class ArcArchiveInfoInsertServiceImpl implements IArcArchiveInfoInsertService {

    private static final Logger log = LoggerFactory.getLogger(ArchiveStorageTaskServiceImpl.class);
    @Autowired
    private IArchiveArchAreaService archiveArchAreaService;
    @Autowired
    private IArchiveStocktakingTaskService archiveStocktakingTaskService;
    @Autowired
    private IArchiveStorageTaskService archiveStorageTaskService;
    @Autowired
    private IArchiveBorrowTaskService archiveBorrowTaskService;
    @Autowired
    private IArchiveDesTaskService archiveDesTaskService;
    @Autowired
    private IArchiveBoxMoveTaskService archiveBoxMoveTaskService;
    @Autowired
    private IArchiveBoxinnerMoveTaskService archiveBoxinnerMoveTaskService;
    @Autowired
    private IArchiveUploadTaskService archiveUploadTaskService;
    @Autowired
    private IArcBoxService arcBoxService;
    @Autowired
    private IArchiveBagService archiveBagService;
    /**
     * 省平台下发档案盘点任务
     *
     * @param issuedParamVo 盘点任务
     * @return 结果
     */
    @Override
    public ResultEntity  insertArchiveTask(IssuedParamVo issuedParamVo) throws ParseException {
        if(ObjectUtil.isEmpty(issuedParamVo.getChannelCode())){
            throw new ServiceException("渠道编号为空，请检查重试！");
        }
        if (ObjectUtil.isEmpty(issuedParamVo.getInteCode())){
            throw new ServiceException("接口编号为空，请检查重试");
        }
        if (ObjectUtil.isEmpty(issuedParamVo.getDasNo())){
            throw new ServiceException("档案室编号为空，请检查重试！");
        }
        if(ObjectUtil.isEmpty(issuedParamVo.getData())){
            throw new ServiceException("业务数据加密字符串为空，请检查重试");
        }
        if(BusinessConstants.HOUSE_LOCATION_ISSUED_NO.equals(issuedParamVo.getInteCode())){
            log.info("库位下发");
            return archiveArchAreaService.insertIssuedArchiveArchArea(issuedParamVo.getData());
        }else if(BusinessConstants.ARCHIVE_STOCKTAKING_TASK_ISSUED_NO.equals(issuedParamVo.getInteCode())){
            log.info("盘点任务下发");
            return archiveStocktakingTaskService.insertIssuedArchiveStocktakingTask(issuedParamVo.getData());
        }else if(BusinessConstants.ARCHIVE_UPLOAD_TASK_ISSUED_NO.equals(issuedParamVo.getInteCode())){
            log.info("转存任务下发");
            return archiveUploadTaskService.insertIssuedArchiveUploadTask(issuedParamVo.getData());
        }else if(BusinessConstants.ARCHIVE_BORROW_TASK_ISSUED_NO.equals(issuedParamVo.getInteCode())){
            log.info("借阅任务下发");
            return archiveBorrowTaskService.insertIssuedArchiveBorrowTask(issuedParamVo.getData());
        }else if (BusinessConstants.ARCHIVE_STORAGE_TASK_ISSUED_NO.equals(issuedParamVo.getInteCode())){
            log.info("入库任务下发");
            return  archiveStorageTaskService.insertIssuedArchiveStorageTask(issuedParamVo.getData());
        }else if (BusinessConstants.NEW_ADD_ARCHIVE_BOX.equals(issuedParamVo.getInteCode())){
            log.info("新增档案盒接口");
            return arcBoxService.insertIssuedArcBox(issuedParamVo.getData());
        }else if (BusinessConstants.NEW_ADD_ARCHIVE_BAG.equals(issuedParamVo.getInteCode())){
            log.info("新增档案袋接口");
            return archiveBagService.insertIssuedArchiveBag(issuedParamVo.getData());
        }else if (BusinessConstants.ARCHIVE_DES_TASK_ISSUED_NO.equals(issuedParamVo.getInteCode())){
            log.info("销毁任务下发");
            return archiveDesTaskService.insertIssuedArchiveDesTask(issuedParamVo.getData());
        }else if (BusinessConstants.ARCHIVE_BOXINNER_MOVE_TASK_ISSUED_NO.equals(issuedParamVo.getInteCode())){
            log.info("档案盒间移位任务下发");
            return archiveBoxinnerMoveTaskService.insertIssuedArchiveBoxinnerMoveTask(issuedParamVo.getData());
        }else if (BusinessConstants.ARCHIVE_BOX_MOVE_TASK_ISSUED_NO.equals(issuedParamVo.getInteCode())){
            log.info("档案盒移位任务下发");
            return archiveBoxMoveTaskService.insertIssuedArchiveBoxMoveTask(issuedParamVo.getData());
        }
        return ResultEntity.success();
    }
}
